package com.cncsi.web;

import com.cncsi.entity.Department;
import com.cncsi.entity.Orders;
import com.cncsi.entity.Project;
import com.cncsi.entity.User;
import com.cncsi.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @RequestMapping(value = "/todepartment",method = RequestMethod.GET)
    public String todepartment(Map<String,Object> map) {
        List<Project> projectList = departmentService.getProjectList();
        map.put("projectList",projectList);

        List<User> userList  = departmentService.getUserList();
        map.put("userList",userList);

        List<Department> departmentList = departmentService.findOrderForAll();
        map.put("departmentList", departmentList);

        return "department/department_index";
    }

    @ResponseBody
    @RequestMapping(value = "/saveDepartment", method = RequestMethod.POST)
    public String saveDepartment(Department department) {
        String result = departmentService.saveDepartment(department);
        return result;
    }


}
